package com.gxa.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis plus配置
 *
 * @author zdk
 * @date 2023/5/4 15:13
 */
@Configuration
public class MybatisPlusConfig {
    @Bean
    public ConfigurationCustomizerImpl mybatisConfigurationCustomizer() {
        return new ConfigurationCustomizerImpl();
    }

    class ConfigurationCustomizerImpl implements ConfigurationCustomizer {
        @Override
        public void customize(MybatisConfiguration configuration) {
            configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
        }
    }

    /**
     * mybatis-plus分页插件所需的拦截器
     * @return MybatisPlusInterceptor
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
